package com.dingdang.mq;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dingdang.entity.OrderDetails;
import com.dingdang.mapper.OrderDetailsMapper;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(consumerGroup = "cancleGroup",topic = "cancel")
public class CancelMq implements RocketMQListener<Long> {

    @Autowired
    private OrderDetailsMapper orderDetailsMapper;

    @Override
    public void onMessage(Long orderId) {
        OrderDetails orderDetails = orderDetailsMapper.selectById(orderId);
        if (orderDetails.getStatus().equals("1")) {
            LambdaUpdateWrapper<OrderDetails> wrapper = new LambdaUpdateWrapper<>();
            wrapper.eq(OrderDetails::getOrderId, orderId).set(OrderDetails::getStatus, "5");
            orderDetailsMapper.update(null, wrapper);
        }
    }
}
